package cn.dt70.service.impl;

import cn.dt70.dao.aqbProduct.AqbProductMapper;
import cn.dt70.pojo.AqbProduct;
import cn.dt70.service.AqbProductService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AqbProductServiceImpl implements AqbProductService {

    private static final Logger LOGGER = Logger.getLogger(AqbProductServiceImpl.class);

    @Resource
    private AqbProductMapper aqbProductMapper;

    @Override
    public boolean addOneProjectDetail(AqbProduct aqbProduct) {

        boolean flag = false;

        try {
            int row = aqbProductMapper.insertOneProDetail(aqbProduct);
            if (row==1){
                flag=true;
            }

        } catch (Exception e) {
            LOGGER.error("AqbProductServiceImpl.addOneProjectDetail --> "+e.getMessage());
        }

        return flag;
    }

    @Override
    public boolean modifyProjectDetail(AqbProduct aqbProduct) {

        boolean flag = false;

        try {
            int row = aqbProductMapper.updateProDetail(aqbProduct);
            if (row==1){
                flag=true;
            }

        } catch (Exception e) {
            LOGGER.error("AqbProductServiceImpl.modifyProjectDetail --> "+e.getMessage());
        }

        return flag;
    }

    @Override
    public AqbProduct findOneProjectDetail(Integer pjId, String proCode) {

        AqbProduct aqbProduct = new AqbProduct();

        try {
            aqbProduct =  aqbProductMapper.selectOneProDetail(pjId,proCode);
        } catch (Exception e) {
            LOGGER.error("AqbProductServiceImpl.findOneProjectDetail --> "+e.getMessage());
        }

        return aqbProduct;
    }

    @Override
    public boolean modifyDetailSummary(Integer pjId, String summary) {
        AqbProduct tempProduct = findOneProjectDetail(pjId,null);
        tempProduct.setpSummary(summary);

        return modifyProjectDetail(tempProduct);
    }

}
